package com.qf.service.Impl;

import com.qf.dao.AccountDao;
import com.qf.pojo.Account;
import com.qf.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @ClassName AccountServiceImpl
 * @Author xiao宋
 * @Date 9:59  2022/9/29
 * @Version 1.0
 * @Description TODO
 */
@Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
@Service
public class AccountServiceImpl implements AccountService {
    @Autowired
    AccountDao accountDao;
    public void transfer(String a, String b, int count) {

//        查钱
        Account aa = accountDao.findByName(a);
        Account bb = accountDao.findByName(b);

//        转钱
        aa.setMoney(aa.getMoney() - count);
        bb.setMoney(bb.getMoney() + count);

//        数据库出账
        accountDao.update(aa);
//        System.out.println(1/0);
        accountDao.update(bb);
    }
}
